/*
package com.xgp.Software.service;

import com.xgp.Software.dto.NotificationDTO;
import com.xgp.Software.dto.PageDTO;
import com.xgp.Software.mapper.NotificationMapper;
import com.xgp.Software.model.Notification;
import com.xgp.Software.model.NotificationExample;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

//@Service
public class NotificationService2 {

    @Autowired
    private NotificationMapper notificationMapper;

    public PageDTO list(Long id, Integer page, Integer size) {

        NotificationExample notificationExample = new NotificationExample();
        notificationExample.createCriteria().andGmtCreateEqualTo(id);

        Integer totalCount = (int)notificationMapper.countByExample(notificationExample);
        totalCount = totalCount == 0 ? 1 : totalCount;
        Integer totalPage = (totalCount % size == 0 ? totalCount /size : totalCount / size + 1);

        if(page < 1) {
            page = 1;
        }
        if(page > totalPage) {
            page = totalPage;
        }

        PageDTO<NotificationDTO> pageDTO = new PageDTO();
        pageDTO.setPagination(totalPage,page);

        if(page < 1) {
            page = 1;
        }
        if(page > pageDTO.getTotalPage()) {
            page = pageDTO.getTotalPage();
        }

        Integer offset = size * (page -1);

        NotificationExample example = new NotificationExample();
        example.createCriteria().andReceiverEqualTo(id);
        example.setOrderByClause("gmt_create desc");
        List<Notification> notifications = notificationMapper.selectByExampleWithRowbounds(example, new RowBounds(offset, size));
//        List<Question> questions = questionMapper.list(offset,size);

        if(notifications.size() == 0) {
            return pageDTO;
        }

        notifications.stream().map(notification -> notification.getNotifier().collect(Collectors.toSet()));

        List<NotificationDTO> notificationDTOList = new ArrayList<>();
        pageDTO.setData(notificationDTOList);
    }
}
*/
